home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CUJ9204.ARJ / 1004106A < prev    next >
Text File  |  1992-06-02  |  1KB  |  61 lines

  1.  
  2. Listing 1
  3.  
  4. **********                                   
  5. #include  <stdio.h>  
  6. #include  <stdlib.h>  
  7. #include  <stdarg.h> 
  8.  
  9. void  myfunction1(char *format, ...)  
  10.     {
  11.     va_list arg_ptr;  
  12.     va_start(arg_ptr,format);  
  13.     vfprintf(stdout,format,arg_ptr);  
  14.     va_end(arg_ptr);  
  15.     }
  16.  
  17. void  myfunction2(char *format, ...)  
  18.     {
  19.     FILE *fp;  
  20.     va_list arg_ptr;  
  21.     fp = fopen("TEST.DAT","a+");
  22.     va_start(arg_ptr,format);  
  23.     vfprintf(fp,format,arg_ptr);  
  24.     va_end(arg_ptr);  
  25.     fclose(fp);
  26.     }
  27.  
  28. void  myfunction3(char *format, ...)  
  29.     {
  30.     va_list arg_ptr1;  
  31.     va_list arg_ptr2;  
  32.     va_start(arg_ptr1,format);
  33.  
  34.     myfunction1(format,arg_ptr1); 
  35.  
  36.     /* here I want to use the  arguments of myfunction3(),  
  37.    va_end(arg_ptr1); but this code does not work */
  38.  
  39.    va_start(arg_ptr2,format);  
  40.    myfunction2(format,arg_ptr2); 
  41.  
  42.    /* here I want to use the  arguments of myfunction3(),  
  43.    va_end(arg_ptr2); but this code does not work */
  44.    }
  45.  
  46. int main()  
  47.    {
  48.    char  msg[]="message";  
  49.    myfunction1("\n%s=%d=%f", msg, 2, 3.0);  /* this works fine */  
  50.    myfunction2("\n%s=%d=%f", msg, 2, 3.0);  /* this works fine */  
  51.  
  52.    /*  the following call of myfunction3() does not work.  
  53.    I want to have the same result, as
  54.    if I call  myfunction1() and myfunction2() isolated  */  
  55.  
  56.    myfunction3("\n%s=%d=%f", msg, 2, 3.0);  
  57.    }
  58.  
  59. *************
  60.  
  61.